﻿@using SmartSiteManagementSystem.Models.User;

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewBag.BodyClass = "easyui-layout";
}

<div id="tbtool" class="gou-toolbar" style="padding:3px;">
     <form method="post" action="/User/HealthMonitorIndex" id="searchForm">
    <span>用户:</span>
            <select  id="combo_selUser" name="combo_selUser" class="easyui-combobox" style="width:150px;">
                
                <option value="-1">请选择</option>
                  @foreach (var item in ViewBag.userList as IList<UserInfo>)
                {

                    <option value="@item.UserId"> @(item.ShowName) </option>
                }

            </select>

    <a href="javascript:;" class="easyui-linkbutton" iconcls="icon-search" onclick="Search();">查找</a>
    <a href="javascript:void(0);" onclick="addOrEditUserHealthMonitor(0);" class="easyui-linkbutton" iconcls="icon-add">新增</a>

             &nbsp;&nbsp;<span>随机生成</span><input id="generalTaskCount" name="generalTaskCount" maxlength="10" value="30" style="line-height:26px;border:1px solid #ccc width:50"><span>条记录</span>
         <a href="javascript:void(0);" onclick="RandomAddData();" class="easyui-linkbutton" iconcls="icon-add">点击生成</a>




        </form>
</div>

<table id="grid" data-options="region:'center',border:false" class="easyui-datagrid"
       rownumbers="true" fitcolumns="true" singleselect="true" fit="true" pagesize="50"></table>

@section Script{

    <script type="text/javascript">
        $(function () {
            function formatOper(val, row, index) {
                var rek = "";
                var cor = "";
                var opt = "";
                opt = opt + '&nbsp;&nbsp;<a href="javascript:void(0);" onclick="addOrEditUserHealthMonitor(\'' + row.LogId + '\');">编辑</a>&nbsp|&nbsp;<a href="javascript:void(0);" onclick="ajaxDeleteUserHealthMonitor(\'' + row.LogId + '\');">删除</a>&nbsp';

                return opt ;
            }
            $('#grid').datagrid({
                url: 'GetHealthMonitorList?userId=-1',
                columns: [[
                     { field: 'LogId', title: 'Id', width: 70 }
                  ,{ field: 'UserName', title: '用户', width: 100 }
                     ,{ field: 'CollectTimeStr', title: '采集时间', width: 100 }
           ,{ field: 'HeartBeat', title: '心跳', width: 150 }
                   ,{ field: 'Temperature', title: '体温', width: 100 }
                ,{ field: 'CreateTimeStr', title: '创建时间', width: 100 }
                    , { field: '_operate', title: '操作', width: 100, align: 'center', formatter: formatOper }
                ]],
                toolbar: '#tbtool',
                pagination: true
            });
            var pager = $('#grid').datagrid('getPager');	// get the pager of datagrid
            pager.pagination({
                showPageList: true,
                pageSize: 50
            });

        });
        function Search() {      
             var selUserId = $("[name=combo_selUser]").val();
            $('#grid').datagrid("load", {
                userId: selUserId
            });
        }

        function ajaxDeleteUserHealthMonitor(id) {
            var rek = "删除";
            $.messager.confirm(rek, "你确定" + rek + "吗?", function (istrue) {
                if (istrue) {
                    var param = { logId: id };
                    $.ajax({
                        "type": "Post",
                        "url": "ajaxDeleteUserHealthMonitor?t=" + new Date().getTime(),
                        "dataType": "json",
                        "data": param,
                        "success": function (data) {
                            if (data.IsSuccess) {
                                $.messager.alert('提示', data.Msg);
                                $("#grid").datagrid("reload");
                            }
                            else
                            {
                                $.messager.alert('提示', data.Msg);
                             }
                        }
                    });
                }
            });
           
        }


        function addOrEditUserHealthMonitor(id) {
            window.location.href = "UserHealthMonitorAccess?id=" + id;
        }



        
        function RandomAddData()
        {

         var selUserId = $("[name=combo_selUser]").val();

        if(selUserId<0)
        {
             $.messager.alert('提示', '请选择用户');
                return false;
        }

               var generalTaskCount = $("#generalTaskCount").val();
            if (generalTaskCount == undefined || generalTaskCount.length == 0) {
                $.messager.alert('提示', '请输入要生成记录条数');
                return false;
            }
            else
           {
       
                var param = { userId: selUserId,generalTaskCount:generalTaskCount };
                $.ajax({
                        "type": "Post",
                        "url": "ajaxGeneralData?t=" + new Date().getTime(),
                        "dataType": "json",
                        "data": param,
                        "success": function (data) {
                            if (data.IsSuccess) {
                                $.messager.alert('提示', data.Msg);
                                $("#grid").datagrid("reload");
                            }
                            else
                            {
                                $.messager.alert('提示', data.Msg);
                             }
                        }
                    });

           }
        }

    </script>
}





